import Mock from 'mockjs'
import mockConfig from './config'

// 检查是否启用mock
if (!mockConfig.enabled) {
  console.log('🚫 Mock服务已禁用')
} else {
  // 设置延迟时间
  Mock.setup({
    timeout: `${mockConfig.timeout.min}-${mockConfig.timeout.max}`
  })

  // 添加请求日志
  if (mockConfig.logEnabled) {
    Mock.mock(/.*/, 'get', (options) => {
      console.log('📡 Mock GET:', options.url)
    })
    
    Mock.mock(/.*/, 'post', (options) => {
      console.log('📡 Mock POST:', options.url, options.body)
    })
    
    Mock.mock(/.*/, 'put', (options) => {
      console.log('📡 Mock PUT:', options.url, options.body)
    })
    
    Mock.mock(/.*/, 'delete', (options) => {
      console.log('📡 Mock DELETE:', options.url)
    })
  }

  // 导入各个模块的mock数据
  import('./modules/auth')
  import('./modules/user')
  import('./modules/menu')
  import('./modules/dashboard')

  console.log('🚀 Mock服务已启动')
  console.log('📊 配置信息:', {
    timeout: `${mockConfig.timeout.min}-${mockConfig.timeout.max}ms`,
    logEnabled: mockConfig.logEnabled,
    errorRate: mockConfig.errorRate,
    delayRate: mockConfig.delayRate
  })
}

// 设置延迟时间
Mock.setup({
  timeout: `${mockConfig.timeout.min}-${mockConfig.timeout.max}`
})

// 添加请求日志
if (mockConfig.logEnabled) {
  Mock.mock(/.*/, 'get', (options) => {
    console.log('📡 Mock GET:', options.url)
  })
  
  Mock.mock(/.*/, 'post', (options) => {
    console.log('📡 Mock POST:', options.url, options.body)
  })
  
  Mock.mock(/.*/, 'put', (options) => {
    console.log('📡 Mock PUT:', options.url, options.body)
  })
  
  Mock.mock(/.*/, 'delete', (options) => {
    console.log('📡 Mock DELETE:', options.url)
  })
}

// 导入各个模块的mock数据
import './modules/auth'
import './modules/user'
import './modules/menu'
import './modules/dashboard'

console.log('🚀 Mock服务已启动')
console.log('📊 配置信息:', {
  timeout: `${mockConfig.timeout.min}-${mockConfig.timeout.max}ms`,
  logEnabled: mockConfig.logEnabled,
  errorRate: mockConfig.errorRate,
  delayRate: mockConfig.delayRate
})

export default Mock 